# -*- coding: utf-8 -*-
# @Time    : 2018/3/31 19:19
# @Author  : Tianchiyue
# @File    : cnn.py
# @Software: PyCharm Community Edition
from models.model import BaseModel
from keras.layers import Conv1D, GlobalMaxPooling1D, concatenate
from models.layers import ClearMaskLayer

class Cnn(BaseModel):
    def build(self):
        sentence = ClearMaskLayer()(self.sentence)
        convs = []
        for ksz in self.config['kernel_sizes']:
            conv = Conv1D(self.config['filters'],
                          ksz,
                          activation='relu')(sentence)
            pooling = GlobalMaxPooling1D()(conv)
            convs.append(pooling)
        merged = concatenate(convs,axis=-1)
        return merged